package com.itheima.tlias84.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlias84.annotation.Log;
import com.itheima.tlias84.dto.SelectAllClazzDTO;
import com.itheima.tlias84.dto.SelectClazzByIdDTO;
import com.itheima.tlias84.entity.Clazz;
import com.itheima.tlias84.mapper.ClazzMapper;
import com.itheima.tlias84.po.InsertClazzParam;
import com.itheima.tlias84.po.SelectClazzPageParam;
import com.itheima.tlias84.po.UpdateClazzParam;
import com.itheima.tlias84.service.ClazzService;
import com.itheima.tlias84.utils.ResultUtil;
import com.itheima.tlias84.vo.PageVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClazzServiceImpl implements ClazzService {

    @Resource
    ClazzMapper clazzMapper;

    @Override
    public ResultUtil selectAllclazzs(SelectClazzPageParam param) {
        Page<Object> page = PageHelper.startPage(param.getPage(), param.getPageSize());
        List<SelectAllClazzDTO> clazzes = clazzMapper.selectAllclazzs(param);
        PageVO<SelectAllClazzDTO> pageVO = new PageVO<>();
        pageVO.setTotal(page.getTotal());
        pageVO.setRows(clazzes);
        return ResultUtil.success(pageVO);
    }

    @Override
    public List<Clazz> selectAll() {
       return clazzMapper.selectAll();
    }

    @Log
    @Override
    public int deleteById(Integer id) {
        return clazzMapper.deleteById(id);
    }

    @Log
    @Override
    public int insertClazz(InsertClazzParam param) {
        return clazzMapper.insertClazz(param);
    }

    @Override
    public SelectClazzByIdDTO selectClazzById(Integer id) {
        SelectClazzByIdDTO dto = clazzMapper.selectClazzById(id);
        return dto;
    }

    @Log
    @Override
    public int updateClazz(UpdateClazzParam param) {
        return clazzMapper.updateClazz(param);
    }
}
